<extend name="Public/base"/>

<block name="body">
<div class="container">
    <div class="row">
        <div class="span12">
            <div class="form-item">
                <label class="item-label">是否需要从头导入<span class="check-tips"></span></label>
                <div class="controls">
                    <label class="radio"><input type="radio" name="all" value="1">是</label>
                    <label class="radio"><input type="radio" name="all" value="0" checked="checked">否</label>
                </div>
            </div>

                <div class="progress progress-success progress-striped active" style="margin: 15px 0">
                    <div class="bar" style="width: 1%;"></div>
                </div>
                <p id="show-msg" class="success">更新进度： 0%</p>

            <div style="margin-top: 15px">
                <span class="btn btn-primary" id="submit">开始更新</span>
                <a class="btn btn-default" href="{:U('index')}">返回</a>
            </div>

        </div>
    </div>
</div>



</block>

<block name="script">
<script type="text/javascript">
    $(function () {
        $("#submit").click(function () {
            $(".alert").show().html("<p>提示：后台任务执行中……</p><p>请尽量不要做其他的操作，以防数据出现混乱。</p>");
            $(this).text('后台处理中').addClass('disabled');
            var all = $('input[name="all"]:checked').val();
            $.post('{:U()}',
                    {all: all}
            );

        });
    })
    var CheckProgress = setInterval(getProgress, 3000);

    function getProgress() {
        $.post("{:U('getProgress')}",
                {name: 'importClient'},
                function (data) {
                    if(data == false){
                        exit();
                    }
                    if(data.progress >= 0 < 100){
                        $(".alert").show().html("<p>提示：后台任务执行中……</p><p>请尽量不要做其他的操作，以防数据出现混乱。</p>");
                        $("#submit").text('后台处理中').addClass('disabled');
                        $(".progress").find(".bar").css('width',data.progress+"%");
                        $("#show-msg").text('更新进度： '+data.progress+'% '+data.msg);

                    }
                    if (data.progress == 100) {
                        clearInterval(CheckProgress);
                        $.post("{:U('getProgress')}", {clear: true, name: 'importClient'});
                    }
                }
        );//end post
    }

</script>
</block>
